<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>会员统计</title>
    <link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.5.5/css/layui.css" media="all">
    <script src="https://minglie.gitee.io/mingpage/static/public/layui/layui.js"></script>
    <script src="https://minglie.gitee.io/ming_node_plugis/src/lib/ming_mock2.5.0.js"></script>
    <script>
        layui.jquery.ajax = M.ajax;
        app.get("/datalist", async (req, res) => {
            console.log("======>",req.params)
            const {page,limit}=req.params;
            console.log(req.params)
            let r= await M.request.get("member_statistics/list",{
                page:page,
                num:limit
            })
            res.send(r)
        })
        app.get("/getTableSchema",async (req, res) =>{
            let r= await M.request.get("member_statistics/getTableSchema");
            let rdate=r.data;
            let rrdata=[]
            for (let i=0;i<rdate.length;i++){
                rdate[i].width=80;

                if(rdate[i].column_name=="company"){
                    rdate[i].width=200;
                }


                if(rdate[i].column_name!="unionid" && rdate[i].column_name!="openid"){
                    rrdata.push(rdate[i])
                }

            }

            let  rdateCol=  rrdata.map(u=>{
                let o={};
                o.field=u["column_name"];
                o.width=u["width"];
                o.title=u["column_comment"];
                o.sort=true;
                return o;
            })
            res.send(rdateCol);
        })

    </script>

    <!--    index.js-->
    <script>
        $ = layui.jquery
        let state = {}
        layui.config({
            version: '1623988781489' //为了更新 js 缓存，可忽略
        });
        //加载模块
        layui.use(async function () { //亦可加载特定模块：layui.use(['layer', 'laydate', function(){
            //得到各种内置组件
            var layer = layui.layer //弹层
                , table = layui.table //表格

            let  tableSchema=await MIO.getTableSchema()

            //执行一个 table 实例
            M.tableObj = table.render({
                elem: '#demo'
                , height: 920
                , url: '/datalist' //数据接口
                , title: '会员统计'
                , page: true //开启分页
                , toolbar: '#toolbarDemo' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
                , totalRow: true //开启合计行
                , cols: [tableSchema]
                ,limits: [500,1000]
                ,limit: 500 ,
                parseData: function (res) { //res 即为原始返回的数据
                    let r = {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.rows //解析数据列表
                    }
                    //console.log(r)
                    return r;
                }
            });
        })


        function renderDictory(parentId) {
            state.parentId = parentId;
            M.tableObj.reload({
                where: {
                    parentId: parentId
                }
                , page: {
                    curr: 1
                }
            });
        }

        $(function () {

        })
    </script>
</head>
<body>

<div class="layui-layout ">



    <div >
        <!-- 内容主体区域 -->
        <div style="padding: 15px;">
            <table class="layui-hide" id="demo" lay-filter="test"></table>
            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-xs" lay-event="lookUseData">查看模板</a>
                <a class="layui-btn layui-btn-xs" lay-event="syncDictionary">同步</a>
            </script>
        </div>
    </div>


    <div class="site-text" style="margin: 5%; display: none" id="window" target="test123">
        <form class="layui-form" id="book" method="post" lay-filter="example">
            <div class="layui-form-item">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-block">
                    <input type="text" id="dictionaryNameId" name="name" lay-verify="title" autocomplete="off"
                           placeholder="请输入编号" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">文档地址</label>
                <div class="layui-input-block">
                    <input type="text" id="useCodeId" name="useCode" lay-verify="title" autocomplete="off"
                           placeholder="请输入名称" class="layui-input">
                </div>
            </div>
        </form>
    </div>
</div>
</body>
</html>


<script type="text/html" id="toolbarDemo">

</script>

